package com.itheima.chapter10.thread.demo10;

public class MyRunnable implements Runnable{
    private  int ticket =100;
    Object obj=new Object();

    @Override
    public void run() {
     while (true){
         synchronized (obj){
             if (ticket>0){
                 try {
                     Thread.sleep(30);
                 } catch (InterruptedException e) {
                     e.printStackTrace();
                 }
                 System.out.println(Thread.currentThread().getName()+"--->正在读第"+ticket+"页");
                 ticket--;

             }
             else {
                 break;
             }
         }
     }

    }
}
